package cn.stronglink.assetmanage.index.adapter;

import android.content.Context;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.index.entity.TaskEntity;
import cn.stronglink.assetmanage.index.holder.MenuHolder;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import freemarker.ext.beans.HashAdapter;

/**
 * @author zww
 * 2018 2018/6/10 18:13
 */
public class ItemMenuAdapter extends RecyclerView.Adapter<MenuHolder> {
    public ArrayMap<Integer, MenuHolder> maps = new ArrayMap<>();
    private Context mContext;
    private List<TaskEntity> datas;
    private onRecyclerListener listener;

    public ItemMenuAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public MenuHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = View.inflate(mContext, R.layout.item_modules, null);
        return new MenuHolder(inflate, listener);
    }

    @Override
    public void onBindViewHolder(MenuHolder holder, int position) {
        if (null != datas) {
            holder.imgModule.setImageResource(datas.get(position).getTaskResuorces());
            holder.tvModuleName.setText(datas.get(position).getTaskText());
            if (position == 0) {
                holder.imgModule.setTagEnable(true);
            }
            maps.put(position, holder);
        }
    }

    @Override
    public int getItemCount() {
        if (null != datas) {
            return datas.size();
        }
        return 0;
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<TaskEntity> data) {
        datas = data;
        notifyDataSetChanged();
    }
}
